package vn.com.mybudget.base;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HTMLView extends ViewBase {
	public HTMLView(Object model,Object root) {
		super(model);
		this.RootExecuter = root;
	}
	
	@Override
	public void Process(HttpServletRequest currentRequest,HttpServletResponse currentResponse ){
		try {
			String path = this.Model.toString();
    		String basePath = this.RootExecuter.getClass().getSimpleName();
    		basePath=basePath.replace("Servlet", "/"+path);
    		basePath = basePath.toLowerCase();
    		if (path.indexOf("jsp")>0){
    			basePath = "/WEB-INF/"+basePath;
    		}
    		else{
    			basePath= "/WEB-INF/"+basePath+".html";	
    		}
    		//currentResponse.getWriter().write(basePath);
			currentRequest.getRequestDispatcher(basePath).forward(currentRequest, currentResponse);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
}
